
class Admin::ProductCaseAttachmentsController < Admin::BaseController

  before_action :find_product_case

  def index
    @product_case_attachments = @product_case.product_case_attachments
  end

  def create
    if params[:image].present?
    @product_case.product_case_attachments << ProductCaseAttachment.new(image: params[:image])

    redirect_to :back
    else
      redirect_to action: :index
    end
  end

  def destroy
    @product_case_attachment = @product_case.product_case_attachments.find(params[:id])
    if @product_case_attachment.destroy
      flash[:notice] = "删除成功"
    else
      flash[:notice] = "删除失败"
    end

    redirect_to :back
  end

  def update
    @product_case_attachment = @product_case.product_case_attachments.find(params[:id])
    @product_case_attachment.weight = params[:weight]
    if @product_case_attachment.save
      flash[:notice] = "修改成功"
    else
      flash[:notice] = "修改失败"
    end

    redirect_to :back
  end

  private

  def find_product_case
    @product_case = ProductCase.find params[:product_case_id]
  end
end
